<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../js/vue.js"></script>
    <style>
        #app{
            background-color:#ccc;
            padding:10px;
        }
        .child{
            background-color:skyblue;
            padding:10px;
        }
    </style>
</head>
<body>
    <div id="app">
        <p>父组件</p>
        <p>msg:{{msg}}</p>
        <!-- <child-comp v-on:click.native="getChildMsg()"></child-comp> -->
        <!-- <child-comp v-on:click="getChildMsg()"></child-comp> -->
        <child-comp ref="aa" v-on:click="getChildMsg"></child-comp>
    </div>
    <template id="child">
        <div class="child">
            <p>子组件</p>
            <p>msg:{{msg}}</p>
            <input type="text" v-model="msg">
            <input type="button" value="得到组件实例" @click="getThis()">
        </div>
    </template>
</body>
<script>
    Vue.component("ChildComp",{
        template:"#child",
        data(){
            return {
                msg:"子组件变量数据"
            }
        },
        watch:{
            // msg(){
            //     this.getThis();
            // }
            msg:{
                handler(nv,ov){
                    console.log(nv,ov);
                    this.getThis();
                },
                deep:true,
                immediate:true
            }
        },
        methods:{
            getThis(){
                console.log(this);
                console.log(this._events);
                console.log(this._events.click[0]);
                // this._events.click[0]();
                // this._events.click[0](this.msg);
                // this._events.click[0](this.msg,123);
                this.$emit("click",this.msg,123,'司马老贼');
                console.log(this.$parent);
                this.$parent.getArg();
            }
        },
        created(){
            console.log("ChildComp");
        },
        // mounted(){
        //     this.getThis();
        // },
        // updated(){
        //     this.getThis();
        // }
    })
    new Vue({
        el:"#app",
        data:{
            msg:""
        },
        methods:{
            getChildMsg(a,b,c){
                console.log("父组件方法");
                console.log(b);
                console.log(c);
                this.msg=a;
            },
            getArg(){
                console.log(this.$children);
                console.log(this.$refs.aa);
            }
        },
        created(){
            console.log("app-vue");
        }
    })
</script>
</html>